var express = require('express');
var router = express.Router();
const cinemaService = require('../service/cinemaService');
/* GET home page. */
router.get('/',async function(req, res, next) {
    let {type,value,current,size} = req.query;
    let searchObj = {};
    let data = await cinemaService.find(searchObj
            ,{current:current||1,size:size||10});
    
    res.send(data);
});
router.get('/films/:id',async function(req,res,next){
    res.send(await cinemaService.findByFilmId(req.params.id));
});
router.post('/',async function(req, res, next) {
    // console.log(JSON.parse(req.body.screens));
    if(req.body.screens){
        req.body.screens = JSON.parse(req.body.screens);
    }
    let data = await cinemaService.insert(req.body);
    
    res.send(data);
});

module.exports = router;
